#include "Config.h"
#include "PrototypeLayer.h"

USING_NS_CC;

cocos2d::CCScene *PrototypeLayer::Scene() {
	//'scene' is an autorelease object
	cocos2d::CCScene *scene = cocos2d::CCScene::create();
	//'layer' is an autorelease object
	PrototypeLayer *layer = PrototypeLayer::create();
	//add layer as a child to scene
	scene->addChild(layer);

	return scene;
}

bool PrototypeLayer::init() {

	if (!cocos2d::CCLayer::init()) {
		return false;
	}

	cocos2d::CCSize visibleSize = cocos2d::CCDirector::sharedDirector()->getVisibleSize();
	cocos2d::CCPoint origin = cocos2d::CCDirector::sharedDirector()->getVisibleOrigin();

	cocos2d::CCMenuItemImage *closeItem = cocos2d::CCMenuItemImage::create("CloseNormal.png", "CloseSelected.png",
		this, menu_selector(PrototypeLayer::MenuCloseCallback));

	closeItem->setPosition(ccp(origin.x + visibleSize.width - closeItem->getContentSize().width / 2,
		origin.y + closeItem->getContentSize().height/2));

	cocos2d::CCMenu *menu = cocos2d::CCMenu::create(closeItem, NULL);
	menu->setPosition(CCPointZero);
	this->addChild(menu, 1);

	this->scheduleUpdate();

	return true;
}

void PrototypeLayer::update(float delta) {
	CCLOG("update");
}

void PrototypeLayer::MenuCloseCallback(cocos2d::CCObject *sender) {
	cocos2d::CCDirector::sharedDirector()->end();
}